package com.fancyy.scm.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.fancyy.scm.R;
import com.fancyy.scm.base.BaseActivity;
import com.fancyy.scm.base.annotation.Layout;
import com.fancyy.scm.base.annotation.Translucent;
import com.fancyy.scm.base.http.BRDataListener;
import com.fancyy.scm.base.http.BRDataTransport;
import com.fancyy.scm.bean.GlideImageLoader;
import com.google.gson.reflect.TypeToken;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

import static com.fancyy.scm.BRConstant.BANNER;

@Translucent
@Layout(R.layout.activity_main)
public class MainActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BRDataTransport.createGet(BANNER)
                .execute(new BRDataListener<List<com.fancyy.scm.bean.Banner>>() {
                    @Override
                    public void onSuccess(List<com.fancyy.scm.bean.Banner>  data) {
                        if (data != null && data.size() > 0) {
                            List<String> images = new ArrayList<>();
                            for (com.fancyy.scm.bean.Banner datum : data) {
                                images.add(datum.url);
//                                images.add("http://img1.imgtn.bdimg.com/it/u=2797725048,4064043653&fm=26&gp=0.jpg");
                            }
                            Banner banner = (Banner) findViewById(R.id.banner);
                            //设置banner样式
                            banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
                            //设置图片加载器
                            banner.setImageLoader(new GlideImageLoader());
                            //设置图片集合
                            banner.setImages(images);
                            //设置banner动画效果
                            banner.setBannerAnimation(Transformer.DepthPage);
                            //设置标题集合（当banner样式有显示title时）
//                            banner.setBannerTitles(titles);
                            //设置自动轮播，默认为true
                            banner.isAutoPlay(true);
                            //设置轮播时间
                            banner.setDelayTime(3000);
                            //设置指示器位置（当banner模式中有指示器时）
                            banner.setIndicatorGravity(BannerConfig.CENTER);
                            //banner设置方法全部调用完毕时最后调用
                            banner.start();
                        }
                    }
                }, new TypeToken<List<com.fancyy.scm.bean.Banner>>(){});

    }

    public void onUserInfoClick(View view) {
        Intent intent = new Intent(this, UserInfoActivity.class);
        startActivity(intent);
    }

    public void onScanningClick(View view) {
        Intent intent = new Intent(this, ScanningActivity.class);
        startActivity(intent);
    }

    public void onTrackingClick(View view) {
        Intent intent = new Intent(this, TrackingSelectionActivity.class);
        startActivity(intent);
    }

    public void onReportClick(View view) {
        Intent intent = new Intent(this, ReportActivity.class);
        startActivity(intent);
    }

    public void onPoManagerInfoClick(View view) {
        showToast("Coming soon ...");
    }

    public void onQualityControlInfoClick(View view) {
        Intent intent = new Intent(this, TrayActivity.class);
        startActivity(intent);
    }
}
